package com.ruoyi.common.utils.gs;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
public class BusinessUtil {


    /**
     * 工商查询的工具类
     * @param keyword
     *
     * {"orderNo":"868363067750827232",
     * "data":{"historyNames":null,"capital":"1000.000000万人民币",
     * "districtCode":"310116","city":"上海市","cityCode":"310000",
     * "companyName":"上海偲睿科技有限公司","operationStartdate":"2017-09-28 00:00:00",
     * "industry":"科学研究和技术服务业","realCapital":null,
     * "legalPersonType":"自然人","province":"上海市","orgCode":"MA1J9Y7X2",
     * "legalPerson":"王娜","lastUpdatedTime":"2023-03-19 16:34:17",
     * "issueDate":"2018-06-20 00:00:00","companyCode":"310116003943589",
     * "companyType":"有限责任公司(自然人独资)","operationEnddate":null,"provinceCode":"310000",
     * "companyStatus":"存续（在营、开业、在册）",
     * "businessScope":"从事电子科技、计算机软硬件科技、计算机信息科技、仪器仪表科技、网络科技专业领域内技术开发、技术转让、技术咨询、技术服务，建筑智能化工程，计算机网络工程，计算机软硬件开发，计算机信息系统集成服务，通信设备及相关产品，通讯器材，电子产品，仪器仪表，机电设备及配件，化工原料及产品（除危险化学品、监控化学品、烟花爆竹、民用爆炸物品、易制毒化学品），环保设备，日用百货销售，从事环保科技、节能科技专业领域内技术开发、技术转让、技术咨询、技术服务，从事货物进口及技术进口业务。\r\n【依法须经批准的项目，经相关部门批准后方可开展经营活动】","establishDate":"2017-09-28 00:00:00","authority":"金山区市场监管局",
     * "companyAddress":"上海市金山区海丰路65号5918室",
     * "district":"金山区","creditNo":"91310116MA1J9Y7X29",
     * "contacts":{"website":[{"note":"偲睿科技","value":"www.siruish.cn"}],
     * "phoneNumber":[{"note":"2021年报","value":"021-52216583"},{"note":"","value":"18516782885"}],
     * "address":[{"note":"工商","value":"上海市金山区海丰路65号5918室"},{"note":"2021年报","value":"上海市闵行区恒南路1355号B411室"},{"note":"2019年报","value":"上海金山区海丰路65号5918室"},{"note":"2017年报","value":"上海闵行区恒南路1355号B212"},{"note":"2020年报","value":"上海闵行区恒南路1355号B411"},{"note":"2018年报","value":"上海闵行区恒南路1355号禾谷文创A306"}],"email":[{"note":"2021年报","value":"postmaster@siruish.cn"},{"note":"2018年报","value":"sophiawang@siruish.cn"}]}}}
     * @return
     */
    public static CompanyInfo searchCompanyInfo( String keyword){
        String key = "keyword="+keyword;
        String host = "https://slycompany.market.alicloudapi.com";
        String path = "/business2/get?"+key;
        String appcode = "5b8de880dcde4f71a98215639cc152fb";
        try {

            RestTemplate restTemplate = new RestTemplate();

            //请求头
            HttpHeaders headers = new HttpHeaders();
            headers.add("Authorization", "APPCODE " + appcode);
            //封装请求头
            HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<MultiValueMap<String, Object>>(headers);
            ResponseEntity<String> exchange = restTemplate.exchange(host + path, HttpMethod.GET, formEntity, String.class);
            String body = exchange.getBody();
            JSONObject entries = JSONUtil.parseObj(body);
            CompanyInfo bean = JSONUtil.toBean(entries.getStr("data"), CompanyInfo.class);
            return bean;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  null;
    }

    public static void main(String[] args) {
        String key = "keyword=上海偲睿科技有限公司";
       System.out.println(searchCompanyInfo("中电科技").toString());
    }

}
